home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / date.arc / INCDAY.PAS < prev    next >
Pascal/Delphi Source File  |  1984-01-01  |  8KB  |  310 lines

  1. PROGRAM Set_Date(INPUT,OUTPUT,DataFile);
  2. {
  3.      This program keeps track of the date from the last time it was set
  4.      using this procedure. The user is given the option of setting the
  5.      time in a format similar to the DOS date function; the other allows
  6.      the date to be set by incrementing the day, one day at a time.
  7.      By Tim MacNary (1984).
  8.  
  9.      When Compiling this using Turbo Pascal, set the Maximum and Minumum
  10.      Dynamic Heap size down to 100 so that the program does not displace
  11.      the operating system.
  12. }
  13. CONST
  14.      Debug=FALSE;
  15. TYPE
  16.      RegType=RECORD
  17.           AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags:INTEGER;
  18.      END;
  19.  
  20. VAR
  21.      CheckProgram:FILE;
  22.      DataFile:FILE OF RegType;
  23.      Reg,Temp:RegType;
  24.      GoodDate:BOOLEAN;
  25.      OK:BOOLEAN;
  26.      Choice:CHAR;
  27.  
  28. PROCEDURE ReadFile(VAR Reg:RegType);
  29. {an ASSIGN must have been previously performed}
  30.  
  31. BEGIN
  32.      {$I-}RESET(DataFile);{$I+};
  33.      IF IOResult<>0 THEN { Error occurred; file does'nt exist on this disk.}
  34.      BEGIN
  35.           Reg.DX:=$101; { Set up some defaults for month, day, and year. }
  36.           Reg.CX:=1984
  37.      END
  38.      ELSE READ(DataFile,Reg); { Read in register settings }
  39. END;
  40.  
  41. PROCEDURE WriteFile(Reg:RegType);
  42. BEGIN
  43.      IF Debug THEN WRITELN('IN WriteFile');
  44.      REWRITE(DataFile);
  45.      WRITE(DataFile,Reg);
  46.      CLOSE(DataFile)
  47. END;
  48.  
  49. PROCEDURE CurseOff;
  50. VAR
  51.    result : RECORD
  52.           ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
  53.           END;
  54. BEGIN
  55.      IF mem[$0000:$0449] = 7 THEN
  56.           result.cx :=$4000
  57.      ELSE
  58.           result.cx:=$2000;
  59.      result.ax:=$0100;
  60.      INTR($10,result);
  61. END;
  62.  
  63. PROCEDURE CurseNorm;
  64. VAR
  65.    result : RECORD
  66.           ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
  67.           END;
  68. BEGIN
  69.      IF mem[$0000:$0449] = 7 THEN
  70.           result.cx :=$0b0c
  71.      ELSE
  72.           result.cx:=$0707;
  73.      result.ax:=$0100;
  74.      INTR($10,result);
  75. END;
  76.  
  77. PROCEDURE PrintMonth(Num:INTEGER);
  78. BEGIN
  79.      CASE Num OF
  80.           1:WRITE('January');
  81.           2:WRITE('Febuary');
  82.           3:WRITE('March');
  83.           4:WRITE('April');
  84.           5:WRITE('May');
  85.           6:WRITE('June');
  86.           7:WRITE('July');
  87.           8:WRITE('August');
  88.           9:WRITE('September');
  89.           10:WRITE('October');
  90.           11:WRITE('November');
  91.           12:WRITE('December')
  92.      END;
  93. END;
  94.  
  95. PROCEDURE PrintDate(REg:RegType);
  96. BEGIN
  97.      PrintMonth(HI(Reg.DX));
  98.      WRITE(' ',LO(Reg.DX),',',Reg.CX)
  99. END;
  100.  
  101. PROCEDURE GetChoice(VAR CH:CHAR;Register:RegType);
  102. VAR
  103.      Reg:RECORD
  104.           AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags:INTEGER;
  105.      END;
  106.  
  107. BEGIN
  108.      ClrScr;
  109.      GotoXY(33,9);
  110.      PrintDate(Register);
  111.      GotoXY(33,11);
  112.      WRITE('      MENU');
  113.      GotoXY(33,12);
  114.      NormVideo;
  115.      WRITE('C');
  116.      LowVideo;
  117.      WRITE('hange year, month and day');
  118.      GotoXY(33,13);
  119.      NormVideo;
  120.      WRITE('I');
  121.      LowVideo;
  122.      WRITE('ncrement day, one day at time');
  123.      GotoXY(33,14);
  124.      NormVideo;
  125.      WRITE('E');
  126.      LowVideo;
  127.      WRITELN('xit with shown date');
  128.      GotoXY(33,15);
  129.      WRITE('Choice > ');
  130.  
  131.      { Read single character input }
  132.      Reg.AX:=$100;
  133.      INTR($21,Reg);
  134.      CH:=UPCASE(LO(Reg.AX));
  135.  
  136. END;
  137.  
  138. PROCEDURE SetDate(VAR Reg:RegType;VAR Good:BOOLEAN);
  139. BEGIN
  140.      IF Debug THEN WRITELN('IN SetDate');
  141.      Reg.AX:=$2B00;
  142.      INTR($21,Reg)
  143. END;
  144.  
  145. PROCEDURE IncrementDay(VAR Reg:RegType;VAR Good:BOOLEAN);
  146. VAR
  147.      Month,Day,Year,NumDays:INTEGER;
  148.      CH:CHAR;
  149.  
  150.      FUNCTION Days_In_Month(Month:INTEGER):INTEGER;
  151.      BEGIN
  152.           CASE Month OF
  153.                9,4,6,11:Days_In_Month:=30;
  154.                2:Days_In_Month:=28;
  155.                ELSE Days_In_Month:=31
  156.           END
  157.      END;
  158.  
  159. BEGIN
  160.      IF Debug THEN WRITELN('IN IncrementDay');
  161.      WITH Reg DO
  162.      BEGIN
  163.           Month:=HI(DX);
  164.           Year:=CX;
  165.           Day:=LO(DX)
  166.      END;
  167.      NumDays:=Days_In_Month(Month);
  168.      ClrScr;
  169.  
  170.      GotoXY(22,24);
  171.      WRITE('Hold down the <Space> key to increment day');
  172.      GotoXY(15,25);
  173.      WRITE('Press <Esc> to abort ; Press any other key to update date');
  174.      GotoXY(37,12);
  175.      WRITE(Month,'/',Day,'/',Year,'     ');
  176.      REPEAT    {UNTIL CH<>' '}
  177.           Reg.AX:=$800;
  178.           INTR($21,Reg);              {Input from keyboard without echo}
  179.           CH:=CHAR(LO(Reg.AX));
  180.           IF CH=' ' THEN
  181.           BEGIN
  182.                Day:=Day+1;
  183.                IF Day>NumDays THEN
  184.                BEGIN
  185.                     Day:=1;
  186.                     Month:=Month+1;
  187.                     IF Month>12 THEN
  188.                     BEGIN
  189.                          GotoXY(30,1);
  190.                          WRITE('H A P P Y  N E W  Y E A R');
  191.                          Month:=1;
  192.                          NumDays:=Days_In_Month(Month);
  193.                          Year:=Year+1;
  194.                     END
  195.                END;
  196.                GotoXY(37,12);
  197.                WRITE(Month,'/',Day,'/',Year,'     ');
  198.           END;
  199.      UNTIL CH<>' ';
  200.      GotoXY(13,24);
  201.      WRITE('                                                           ');
  202.      GotoXY(13,25);
  203.      IF ORD(CH)<>27 THEN
  204.      BEGIN
  205.           WRITE('                     DATE UPDATED                           ');
  206.           Good:=TRUE
  207.      END
  208.      ELSE BEGIN
  209.           WRITE('                    DATE UNCHANGED                          ');
  210.           Good:=FALSE
  211.      END;
  212.      WITH Reg DO
  213.      BEGIN
  214.           CX:=Year;
  215.           DX:=(Month SHL 8)+Day
  216.      END;
  217. END;
  218.  
  219. PROCEDURE SetEntireDate(VAR Reg:RegType;VAR OK:BOOLEAN);
  220. VAR
  221.      Year,Month,Day:INTEGER;
  222. BEGIN
  223.      IF DEBUG THEN WRITELN('IN SetEntireDate');
  224.      ClrScr;
  225.      WITH Reg DO
  226.      BEGIN
  227.           Month:=HI(DX);
  228.           Year:=CX;
  229.           Day:=LO(DX)
  230.      END;
  231.  
  232.      {Set year}
  233.      GotoXY(24,11);
  234.      WRITE('Current setting > ',Year,'  ');
  235.      GotoXY(30,12);
  236.      WRITE(' New Year > 19');
  237.      READLN(Year);
  238.      Year:=Year+1900;
  239.  
  240.      {Set month}
  241.      GotoXY(24,11);
  242.      WRITE('Current setting > ',Month,'  (');
  243.      PrintMonth(Month);
  244.      WRITE(')');
  245.      GotoXY(30,12);
  246.      WRITE('New Month >                     ');
  247.      GotoXY(42,12);
  248.      READLN(Month);
  249.  
  250.      {Set day}
  251.      GotoXY(24,11);
  252.      WRITE('Current setting > ',Day,'                     ');
  253.      GotoXY(30,12);
  254.      WRITE('  New Day >                      ');
  255.      GotoXY(42,12);
  256.      READLN(Day);
  257.      IF Debug THEN WRITE('Year>',Year,'Month>',Month,'Day>',Day);
  258.      GotoXY(30,25);
  259.      IF (Year>0) AND (Month>0) AND (Month<=12) AND (Day>0) AND (Day<=31) THEN
  260.      WITH Reg DO
  261.      BEGIN
  262.           Ok:=TRUE;
  263.           GotoXY(35,25);
  264.           WRITE('DATE UPDATED');
  265.           CX:=Year;
  266.           DX:=(Month SHL 8)+Day
  267.      END
  268.      ELSE BEGIN
  269.           WRITE('DATE UNCHANGED');
  270.           Ok:=FALSE
  271.      END
  272. END;
  273.  
  274. BEGIN
  275.      LowVideo;
  276.      GoodDate:=TRUE;
  277.      ASSIGN(DataFile,'DATE.DAT');
  278.  
  279.      ReadFile(Reg);
  280.      Temp:=Reg;         {Save current settings}
  281.      CurseOff;
  282.  
  283.      REPEAT
  284.           GetChoice(Choice,Reg);
  285.           CASE Choice OF
  286.                'C':SetEntireDate(Reg,Ok);
  287.                'I':IncrementDay(Reg,Ok);
  288.                'E':BEGIN
  289.                         NormVideo;
  290.                         GotoXY(30,25);
  291.                         WRITE('Exiting...');
  292.                         Ok:=FALSE
  293.                     END;
  294.                ELSE BEGIN
  295.                     GotoXY(30,15);
  296.                     WRITE('Please enter an "C" or an "I"   ');
  297.                     Delay(2000)
  298.                END;
  299.           END
  300.      UNTIL Choice IN ['C','I','E'];
  301.  
  302.      CurseNorm;
  303.      IF OK THEN
  304.      BEGIN
  305.           SetDate(Reg,GoodDate);
  306.           WriteFile(Reg)
  307.      END
  308.      ELSE
  309.           SetDate(Temp,GoodDate);
  310. END.